package com.itheima.d5_map_traverse;

import java.util.*;

/**
 * @ClassName Exercise
 * @Author 16799
 * @Date 2025/8/12 16:44
 * @Version 1.0
 * @Description TODO
 *
 *  自己写一遍
 **/
public class Exercise {
    public static void main(String[] args) {
        String choose[] = {"A","B","C","D"};
        List<String> data = new ArrayList<>();
        Random r = new Random();
        for (int i = 0; i < 80; i++) {
            int index = r.nextInt(4);
            data.add(choose[index]);
        }
        System.out.println(data);

        Map<String,Integer> last = new HashMap<>();
        data.forEach(s -> {
            if (last.containsKey(s)){
                last.put(s,last.get(s)+1);
            }else {
                last.put(s,1);
            }
        });

        System.out.println("最终的投票结果");
        System.out.println(last);
    }
}
